package com.example.yueliang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.yueliang.dto.HotelDto;
import com.example.yueliang.mapper.HotelMapper;
import com.example.yueliang.pojo.Hotel;
import com.example.yueliang.pojo.HotelRoomCategories;
import com.example.yueliang.service.HotelService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl extends ServiceImpl<HotelMapper, Hotel> implements HotelService {

    @Autowired
    private HotelRoomCategoriesImpl hotelRoomCategories;
    @Override
    public HotelDto getIdWithHotelRoom(Integer id) {
        //查询酒店信息表
        LambdaQueryWrapper<Hotel> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(Hotel::getHid,id);

        Hotel hotel1 = this.getOne(queryWrapper1);

        HotelDto hotelDto = new HotelDto();

        BeanUtils.copyProperties(hotel1,hotelDto);

        //查询酒店房型分类表
        LambdaQueryWrapper<HotelRoomCategories> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.eq(HotelRoomCategories::getHid,id);
        List<HotelRoomCategories> list = hotelRoomCategories.list(queryWrapper2);

        hotelDto.setHotelRoomCategories(list);
        return hotelDto;
    }
}
